]> dgit.raspbian.org Git - libreoffice.git/commitdiff
[PATCH] put calc external data mappings under link update control
authorCaolán McNamara <caolan.mcnamara@collabora.com>
Sat, 11 Jul 2026 23:36:15 +0000 (23:36 +0000)
committerRene Engelhard <rene@debian.org>
Sat, 3 Oct 2026 10:46:08 +0000 (12:46 +0200)
register each mapping as a LinkManager link, so its refresh goes through
the same update control as sheet links and area links. Wait until after
the infobar-controlled update mode is known to update.

Signed-off-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Change-Id: I6710d4bdf3de6e002365d75c911b69076a054da8
Reviewed-on: https://gerrit.collaboraoffice.com/c/core/+/7058
Tested-by: Jenkins CPCI <releng@collaboraoffice.com>
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
(cherry picked from commit b72d760465c857eb5dd10cdc45b107c49bb0caec)
Signed-off-by: Xisco Fauli <xiscofauli@libreoffice.org>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/208394
Tested-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Gbp-Pq: Name CVE-2026-63267-1.diff

sc/inc/datamapper.hxx
sc/inc/document.hxx
sc/source/core/data/document10.cxx
sc/source/core/tool/ddelink.cxx
sc/source/core/tool/webservicelink.cxx
sc/source/filter/xml/xmlmappingi.cxx
sc/source/filter/xml/xmlmappingi.hxx
sc/source/ui/dataprovider/dataprovider.cxx
sc/source/ui/docshell/docsh4.cxx
sc/source/ui/docshell/tablink.cxx
sc/source/ui/view/tabvwsh4.cxx

index 984e6cc8121957dcab42fb17c83ed0573eb79122..32d610ac3c9bb065c6a9730df4f5a2185e820a82 100644 (file)
@@ -96,7 +96,7 @@ public:
 
 class SC_DLLPUBLIC ExternalDataMapper
 {
-    //ScDocument& mrDoc;
+    ScDocument& mrDoc;
     std::vector<ExternalDataSource> maDataSources;
 
 public:
index 7908be80dcc72422a99d193660c38fdb29755bbe..0c0a86177987cb793a0e1f4bb893ced7bb98754e 100644 (file)
@@ -899,6 +899,10 @@ public:
     SC_DLLPUBLIC ScDBData*       GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2);
     void                         RefreshDirtyTableColumnNames();
     SC_DLLPUBLIC sc::ExternalDataMapper& GetExternalDataMapper();
+    /** True when the document holds at least one external data mapping. Checks
+        without creating the mapper, so it stays cheap for documents that have
+        none. */
+    SC_DLLPUBLIC bool HasDataProviderMappings() const;
 
     SC_DLLPUBLIC const ScRangeData* GetRangeAtBlock( const ScRange& rBlock, OUString& rName,
                                                      bool* pSheetLocal = nullptr ) const;
index 4c6527304a7ea6c5cc02e8d0dab2ad08c2b26e95..be8f08adaeaf86bca41ca7b9ca5f858366abe23d 100644 (file)
@@ -1021,6 +1021,11 @@ sc::ExternalDataMapper& ScDocument::GetExternalDataMapper()
     return *mpDataMapper;
 }
 
+bool ScDocument::HasDataProviderMappings() const
+{
+    return mpDataMapper && !mpDataMapper->getDataSources().empty();
+}
+
 void ScDocument::StoreTabToCache(SCTAB nTab, SvStream& rStrm) const
 {
     const ScTable* pTab = FetchTable(nTab);
index 4c854321509eb2b86741d6d394fe516118dd5d86..c66f343cc8a4942a5475cfa69ad206a2b0b6d74d 100644 (file)
@@ -17,6 +17,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <comphelper/embeddedobjectcontainer.hxx>
 #include <comphelper/fileformat.h>
 #include <comphelper/string.hxx>
 #include <osl/thread.h>
@@ -29,6 +30,7 @@
 
 #include <ddelink.hxx>
 #include <brdcst.hxx>
+#include <docsh.hxx>
 #include <document.hxx>
 #include <scmatrix.hxx>
 #include <patattr.hxx>
@@ -125,6 +127,10 @@ void ScDdeLink::Store( SvStream& rStream, ScMultipleWriteHeader& rHdr ) const
 sfx2::SvBaseLink::UpdateResult ScDdeLink::DataChanged(
     const OUString& rMimeType, const css::uno::Any & rValue )
 {
+    if (rDoc.GetDocumentShell()
+        && !rDoc.GetDocumentShell()->GetEmbeddedObjectContainer().getUserAllowsLinkUpdate())
+        return SUCCESS;
+
     //  we only master strings...
     if ( SotClipboardFormatId::STRING != SotExchange::GetFormatIdFromMimeType( rMimeType ))
         return SUCCESS;
index fb5d81afc87b775f6b070e7364dbe8d480e83c05..cbb226e240a84b083d4d3a1d16d69c61a4041848 100644 (file)
@@ -7,6 +7,7 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
+#include <comphelper/embeddedobjectcontainer.hxx>
 #include <comphelper/processfactory.hxx>
 #include <sfx2/linkmgr.hxx>
 #include <sfx2/bindings.hxx>
@@ -21,6 +22,7 @@
 #include <utility>
 #include <webservicelink.hxx>
 #include <brdcst.hxx>
+#include <docsh.hxx>
 #include <document.hxx>
 #include <sc.hrc>
 
@@ -36,6 +38,10 @@ ScWebServiceLink::~ScWebServiceLink() {}
 
 sfx2::SvBaseLink::UpdateResult ScWebServiceLink::DataChanged(const OUString&, const css::uno::Any&)
 {
+    if (pDoc && pDoc->GetDocumentShell()
+        && !pDoc->GetDocumentShell()->GetEmbeddedObjectContainer().getUserAllowsLinkUpdate())
+        return SUCCESS;
+
     aResult.clear();
     bHasResult = false;
 
index 9e9b23e36a986551275db7027c2d63688abe7d25..2048c929d21c04212d68bf4490328ebfc0c55347 100644 (file)
@@ -111,15 +111,6 @@ ScXMLMappingContext::ScXMLMappingContext( ScXMLImport& rImport,
     }
 }
 
-ScXMLMappingContext::~ScXMLMappingContext()
-{
-    ScDocument* pDoc = GetScImport().GetDocument();
-    auto& rDataMapper = pDoc->GetExternalDataMapper();
-    auto& rDataSources = rDataMapper.getDataSources();
-    if(!rDataSources.empty())
-        rDataSources[0].refresh(pDoc, true);
-}
-
 uno::Reference<xml::sax::XFastContextHandler>
     SAL_CALL ScXMLMappingContext::createFastChildContext(
         sal_Int32 nElement, const uno::Reference<xml::sax::XFastAttributeList>& /*xAttrList*/)
index cc38d40dbe939eeecf672f536f9d4898cdf98100..98a74a7eff3107748fe5f455c2ce45da7a45178b 100644 (file)
@@ -34,8 +34,6 @@ public:
     ScXMLMappingContext( ScXMLImport& rImport,
                         const rtl::Reference<sax_fastparser::FastAttributeList>& rAttrList );
 
-    virtual ~ScXMLMappingContext() override;
-
     virtual css::uno::Reference<css::xml::sax::XFastContextHandler> SAL_CALL createFastChildContext(
         sal_Int32 nElement,
         const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList) override;
index 3c3302c23c58974d0a85f90958b0caad0c4342f2..0a6eab303aa5be8216adc67df2201fbd461b5465 100644 (file)
 #include <datamapper.hxx>
 #include <dbdata.hxx>
 #include <docsh.hxx>
+#include <document.hxx>
+#include <comphelper/embeddedobjectcontainer.hxx>
+#include <sfx2/lnkbase.hxx>
+#include <sfx2/linkmgr.hxx>
 #include <utility>
 
 using namespace com::sun::star;
@@ -187,8 +191,46 @@ const std::vector<std::shared_ptr<sc::DataTransformation>>& ExternalDataSource::
     return maDataTransformations;
 }
 
-ExternalDataMapper::ExternalDataMapper(ScDocument& /*rDoc*/)
-    //mrDoc(rDoc)
+namespace {
+
+// A data mapping fetches external data (CSV, HTML, XML) into a sheet. It is
+// registered in the LinkManager so it passes through the same link update
+// control as sheet links, area links, and external references. The link holds
+// the index of its data source in the mapper. That index is stable because
+// data sources are only ever appended, never removed.
+class ScDataProviderLink final : public sfx2::SvBaseLink
+{
+    ScDocShell& mrDocShell;
+    size_t mnSourceIndex;
+
+public:
+    ScDataProviderLink(ScDocShell& rDocShell, size_t nSourceIndex)
+        : sfx2::SvBaseLink(SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::SIMPLE_FILE)
+        , mrDocShell(rDocShell)
+        , mnSourceIndex(nSourceIndex)
+    {
+    }
+
+    virtual sfx2::SvBaseLink::UpdateResult DataChanged(const OUString&,
+                                                       const css::uno::Any&) override
+    {
+        if (!mrDocShell.GetEmbeddedObjectContainer().getUserAllowsLinkUpdate())
+            return SUCCESS;
+
+        ScDocument& rDoc = mrDocShell.GetDocument();
+        std::vector<sc::ExternalDataSource>& rSources
+            = rDoc.GetExternalDataMapper().getDataSources();
+        if (mnSourceIndex < rSources.size())
+            rSources[mnSourceIndex].refresh(&rDoc, true);
+
+        return SUCCESS;
+    }
+};
+
+}
+
+ExternalDataMapper::ExternalDataMapper(ScDocument& rDoc)
+    : mrDoc(rDoc)
 {
 }
 
@@ -199,6 +241,19 @@ ExternalDataMapper::~ExternalDataMapper()
 void ExternalDataMapper::insertDataSource(const sc::ExternalDataSource& rSource)
 {
     maDataSources.push_back(rSource);
+
+    ScDocShell* pDocShell = mrDoc.GetDocumentShell();
+    if (!pDocShell)
+        return;
+
+    sfx2::LinkManager* pLinkManager = mrDoc.GetLinkManager();
+    if (!pLinkManager)
+        return;
+
+    ScDataProviderLink* pLink = new ScDataProviderLink(*pDocShell, maDataSources.size() - 1);
+    const OUString& rProvider = rSource.getProvider();
+    pLinkManager->InsertFileLink(*pLink, sfx2::SvBaseLinkObjectType::ClientFile,
+                                 rSource.getURL(), &rProvider, nullptr);
 }
 
 const std::vector<sc::ExternalDataSource>& ExternalDataMapper::getDataSources() const
index f9744533772a1e2136bd09c5a7a57e98eb1cd670..7efc8ffa04839de36bca94b3eac24dfe1521e192 100644 (file)
@@ -500,6 +500,7 @@ void ScDocShell::Execute( SfxRequest& rReq )
                             rHelpBtn.set_label(GetStandardText(StandardButtonType::Help).replaceFirst("~", ""));
                             rHelpBtn.connect_clicked(LINK(nullptr, LinkHelp, DispatchHelpLinksHdl));
                             weld::Button& rBtn = pInfoBar->addButton();
+                            rBtn.set_buildable_name(u"allowupdating"_ustr);
                             rBtn.set_label(ScResId(STR_ENABLE_CONTENT));
                             rBtn.set_tooltip_text(ScResId(STR_ENABLE_CONTENT_TOOLTIP));
                             rBtn.connect_clicked(LINK(this, ScDocShell, ReloadAllLinksHdl));
index 09a5f674089e7f06baa14899686e0dd2d32a8e56..9a81793c2c7522a52f898ec3b272ae208e206d76 100644 (file)
@@ -35,6 +35,7 @@
 #include <tools/urlobj.hxx>
 #include <unotools/transliterationwrapper.hxx>
 #include <comphelper/configuration.hxx>
+#include <comphelper/embeddedobjectcontainer.hxx>
 #include <comphelper/processfactory.hxx>
 
 #include <tablink.hxx>
index 0e5abc8390e328486f73e4befd32052e528b05c3..f7908b6a7358804937c176e05f7fa7771a7f0b54 100644 (file)
@@ -1632,7 +1632,8 @@ void ScTabViewShell::Construct( TriState nForceDesignMode )
             if (!bLink)
             {
                 const sc::DocumentLinkManager& rMgr = rDoc.GetDocLinkManager();
-                if (rDoc.HasLinkFormulaNeedingCheck() || rDoc.HasAreaLinks() || rMgr.hasExternalLinks())
+                if (rDoc.HasLinkFormulaNeedingCheck() || rDoc.HasAreaLinks()
+                        || rDoc.HasDataProviderMappings() || rMgr.hasExternalLinks())
                     bLink = true;
             }
             if (bLink)